
{
    console.log(`\u{0061}`)
}
{
    let s = '𠮷𠮷a';
    console.log(s.charAt(0))
    console.log(s.charCodeAt(0))
    console.log(s.codePointAt(4).toString(16))
}
{
    let str = '\u{20bb7}abc';
    for(let es6 of str){
        console.log(es6)
    }
}

{
    let user = {
        name: 'list',
        info: 'hello world'
    };
    console.log(abc`i am ${user.name},${user.info}`);
    function abc(s, v1, v2) {
        console.log(s, v1, v2);
        return s + v1 + v2
    }
}
{
    let list = new Set()
    console.log(list)
}
{
    // proxy解耦业务代码
    function validator(target, validator) {
        return new Proxy(target, {
            _validator: validator,
            set(target, key, value){
                if(target.hasOwnProperty(key)){
                    let va = this._validator[key]
                    console.log(va(value))
                    if(!!va(value)){
                        return Reflect.set(target,key,value)
                    }else{
                        throw Error(`不能设置${key}的值为${value}`)
                    }
                }else{
                    throw Error(`${key}不存在`)
                }
            }
        })
    }

    // 配置项
    const validators ={
        name(val){
            return typeof val === 'string'
        },
        age(val){
            return typeof val === 'number' && val > 18
        }
    }

    class Person{
        constructor(name,age){
            this.name = name
            this.age = age
            return validator(this,validators)
        }
    }

    const person = new Person('lilei', 30)
    console.log(person)
    person.name = 'han meimei'
    console.info(person)
    // person.name = 18
    // console.log(person)

}
// {
//     function loadImg(src) {
//         return new Promise((resolve, reject)=>{
//             resolve()
//         })
//     }
// }
{
    let obj = {}
    obj[Symbol.iterator] = function *() {
        yield 1;
        yield 2;
        yield 3;
    }
    for(let val of obj){
        console.log(val)
    }
}
{
    // let status = async function () {
    //     while(1){
    //         await 'a';
    //         await 'b';
    //         await 'c';
    //     }
    // }  
    // let state = status()
    // console.log(state)
    // console.log(state.next()) 
    // console.log(state.next()) 
    // console.log(state.next()) 
    // console.log(state.next()) 
}
// {
//     async function foo(params) {
//         return await 1
//     }
//     foo().then((val)=>{
//         console.log(val);
        
        
//     })
// }
{
    let draw = function(count) {
        console.log('剩余'+count+'次');
        
    }
    let Count = function * (count){
        while(--count >= 0){
            yield draw(count)
        }
    }
    let start = Count(5)
    console.log(start)
    let btn = document.createElement('button');
    btn.textContent = '抽奖'
    btn.id = 'start'
    document.body.appendChild(btn);
    document.getElementById('start').addEventListener('click',function(){
        console.log(666)
        start.next();
    },false)

}
// 轮训方法

{
    function *ajax(){
        return new Promise((resolve, reject)=>{
            setTimeout(() => {
                resolve({
                    code: 1
                }) 
            }, 200);
        })
    }

    function pull(params) {
        let ret = ajax();
        let step = ret.next()
        step.value.then((obj)=>{
            if (obj.code !== 0) {
                setTimeout(() => {
                    console.log(222)
                    pull()

                }, 2000);
            } else {
                console.log(obj.code)
            }
        })
       
    }
    // pull();
}
{
    // 修饰器
    let readonly = function(target, name, descriptor) {
        descriptor.writable = true;
        return descriptor
    }
    class Test {
        @readonly
        time() {
            return '2018-03-11'
        }
    }
    let test = new Test()
    // console.log(test.time= '123')

}
{
    let typename = function (target, name, descriptor) {
        target.myname = 'hello'
    }
    @typename 
    class Test {}
    console.log(Test.myname)
}

//埋点修饰
{
    let log = (type)=>{
        return function (target, name, descriptor) {
            let src_method = descriptor.value;
            console.log(descriptor)
            descriptor.value=function(...arg){
                console.log(this)
                src_method.apply(this, arg)
                console.log(`log ${type}`)
            }
        }
    }

    class AD {
        @log('show')
        show(){
            console.log('ad is show');
            
        }
        @log('click')
        click(){
            console.log('ad is click')
        }
    }
    let ad = new AD()
    ad.show();
    // ad.click();
}